package com.xvyy.tingshu.account.api;

import com.xvyy.tingshu.account.service.UserAccountService;
import com.xvyy.tingshu.common.login.annotation.TsLogin;
import com.xvyy.tingshu.common.result.Result;
import com.xvyy.tingshu.common.util.AuthContextHolder;
import com.xvyy.tingshu.model.account.UserAccountDetail;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account/userAccount")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserAccountApiController {

	@Autowired
	private UserAccountService userAccountService;


	// http://192.168.217.1:8500/api/account/userAccount/getAvailableAmount
	@GetMapping("getAvailableAmount")
	@Operation(summary = "获取可用余额")
	@TsLogin
	public Result<BigDecimal> getAvailableAmount() {
		BigDecimal bigDecimal = userAccountService.getAvailableAmount();
		return Result.ok(bigDecimal);
	}

	// http://192.168.217.1:8500/api/account/userAccount/findUserConsumePage/1/10
	@GetMapping("/findUserConsumePage/{pn}/{pz}")
	@TsLogin
	@Operation(summary = "分页查询消费记录")
	public Result findUserConsumePage(@PathVariable(value = "pn") Long pn,
									  @PathVariable(value = "pz") Long pz) {
		IPage<UserAccountDetail> iPage = new Page<UserAccountDetail>(pn, pz);
		iPage = userAccountService.findUserConsumePage(iPage);
		return Result.ok(iPage);
	}

	// http://192.168.217.1:8500/api/account/userAccount/findUserRechargePage/1/10
	@GetMapping("/findUserRechargePage/{pn}/{pz}")
	@TsLogin
	@Operation(summary = "分页查询充值记录")
	public Result findUserRechargePage(@PathVariable(value = "pn") Long pn,
									   @PathVariable(value = "pz") Long pz) {
		IPage<UserAccountDetail> iPage = new Page<UserAccountDetail>(pn, pz);
		iPage = userAccountService.findUserRechargePage(iPage, AuthContextHolder.getUserId());
		return Result.ok(iPage);
	}
}

